package com.useeinfo.oa.modules.base.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.StringConverters;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 * @Auther: xudong.sun
 * @Date: 2018/11/30 11:10
 * @Description: 字典信息表
 */
@Entity
@Table(name = "dict_info")
public class DictInfo  extends SuperClassEntity<DictInfo> {

    /**
     * 属性名称
     */
    private String propertyName;

    /**
     * 属性编码 紧急程度时此字段为颜色编号YELLOW RED，为空为GREEN
     */
    private String propertyCode;


    /**
     * 类型名称
     */
    private String typeName;

    /**
     * 类型编码
     */
    private String typeCode;

    /**
     * 所属企业
     */
    @ManyToOne
    @JoinColumn(name = "enterprise_id")
    private Enterprise enterprise;

    public String getPropertyName() {
        return propertyName;
    }

    public void setPropertyName(String propertyName) {
        this.propertyName = propertyName;
    }

    public String getPropertyCode() {
        return propertyCode;
    }

    public void setPropertyCode(String propertyCode) {
        this.propertyCode = propertyCode;
    }

    public String getTypeName() {
        return typeName;
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }

    public String getTypeCode() {
        return typeCode;
    }

    public void setTypeCode(String typeCode) {
        this.typeCode = typeCode;
    }

    public Enterprise getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = enterprise;
    }

    @Override
    public JSONObject toJSONObject(){
        JSONObject jsonObject = super.toJSONObject();
        jsonObject.put("propertyName", StringConverters.null2String(getPropertyName()));
        jsonObject.put("propertyCode", StringConverters.null2String(getPropertyCode()));
        jsonObject.put("typeName",StringConverters.null2String(getTypeName()));
        jsonObject.put("typeCode",StringConverters.null2String(getTypeCode()));
        jsonObject.put("enterpriseName", getEnterprise() == null ? "" : StringConverters.null2String(getEnterprise().getEnterpriseName()));

        return jsonObject;
    }
}
